<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>添加用户·思通投研·让数据驱动投资价值!</title>
	<link href="${pageContext.request.contextPath }/img/webLogoIcon.png" rel="shortcut icon">
	<link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/font-awesome.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/style.css" rel="stylesheet">
	<!-- Toastr style -->
	<link href="${pageContext.request.contextPath }/css/plugins/toastr/toastr.min.css" rel="stylesheet">

	<style type="text/css">
	.form-group{
		margin-bottom: 18px;
	}
	.phonetip{
		color: red;
		display: inline;
		float: right;
	}
	</style>
</head>

<body id="wrapper">
	<nav class="navbar-default navbar-static-side" role="navigation">
        <%request.setAttribute("LEFT", "user");%>
		<%@include file="left.jsp"%>
    </nav>
    <div id="page-wrapper" class="gray-bg">
	    <div class="row border-bottom">
	     	<jsp:include page="head.jsp" flush="true" /> 
	    </div>
	    <div class="row wrapper border-bottom white-bg page-heading">
	        <div class="col-lg-9">
	            <h2>添加用户</h2>
	        </div>
	    </div>
	    <div class="middle-box text-center loginscreen   animated fadeInDown">
	        <div>
	            <div>
	
	                <h1 class="logo-name"> </h1>
	
	            </div>
	            
	            <form class="m-t" role="form" action="javascript:void(0)" >
	           		<div class="form-group">
	                    <input type="text" name="institution_name" id="institution_name" class="form-control" placeholder="机构名称" required="">
	                </div>
	                <div class="form-group">
	                    <input type="text" name="username" id="username" onkeyup="value=value.replace(/[^(\-)+\d+(\.\d*)?$]/g,'');" class="form-control" placeholder="手机号" required="">
	                	<font class="phonetip" id="phonetip" style="display:none;">请输入正确的手机号</font>
	                </div>
	                <div class="form-group">
	                    <input type="text" name="name" id="name" class="form-control" placeholder="姓名" required="">
	                </div>
	                <div class="form-group">
	                    <input type="text" name="password" id="password" value="123456" class="form-control" placeholder="密码" required="">
	                </div>
	                <div class="form-group">
	                    <select class="form-control m-b" id="select" name="type">
							<option value="2">普通用户</option>
							<option value="1">管理员</option>
						</select>
	                </div>
	                
	                <button style="margin-top: 55px;" id="sumit" class="btn btn-primary block full-width m-b" >添加</button>
	            </form>
	        </div>
	        
	    </div>
	    <jsp:include page="footer.jsp" flush="true" />
    </div>

    <!-- Mainly scripts -->
	<script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
	<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath }/js/plugins/metisMenu/jquery.metisMenu.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
	<!-- Custom and plugin javascript -->
	<script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/plugins/pace/pace.min.js"></script>
	<!-- Toastr script -->
    <script src="${pageContext.request.contextPath }/js/plugins/toastr/toastr.min.js"></script>
<script type="text/javascript">
	$(function(){
		
	});
	$('#sumit').click(function(){
		var username = $("#username").val();
		var name = $("#name").val();
		var password = $("#password").val();
		var institution_name = $("#institution_name").val();
		if(username == "" || username == null || name == "" || name == null || password == "" || password == null || institution_name == "" || institution_name == null){
			return;
		}else{
			var option = $("#select option:selected"); //获取选中的项
			var power = option.val();
			var data= {username:username,password:password,name:name,power:power,institution_name:institution_name};
			regist(data);
		}
	});
	function regist(data){
		$.ajax({
	        type:"POST",
	        url:"${pageContext.request.contextPath}/regist",
	        data:data,
			dataType:'json',
			success:function(result){
	  			toastr.success('添加成功！');
	  			setTimeout(function () {
  					window.location.href = "${pageContext.request.contextPath}/userList?pageNum=1";
   				}, 1000);
			},
		});
	}
	//验证手机
    $("#username").blur("blur",function(){
        var telphone = $("#username").val();
        /* if(telphone == ""){
        } */
        if(!(!telphone)){
            if(telRuleCheck2(telphone)){
            	
            	$.ajax({
        	        type:"POST",
        	        url:"${pageContext.request.contextPath}/ifUserExist",
        	        data : {
        	        	username:telphone
					},
        			success:function(result){
        				if(result.status == 200){
        					$("#phonetip").attr("style","display:none;");
        					$("#sumit").attr("disabled",false);
        				}else{
        					$("#phonetip").attr("style","color: red;display: inline;float: right;");
        					$("#phonetip").html("该手机号已注册");
        					$("#sumit").attr("disabled","true");
        				}
        			},
        		});
            }
            else
            {
                $("#phonetip").attr("style","color: red;display: inline;float: right;");
                $("#phonetip").html("请输入正确的手机号码");
                $("#sumit").attr("disabled","true");
            };
        };
    });
    telRuleCheck2 = function (string) {
    	var pattern = /^1[3456789]\d{9}$/;
    	if (pattern.test(string)) {
    		return true;
    	}
    	return false;
    };
	//跑马灯方法 
// 	 function init(){
// 		    //获取标题
// 		    var title=document.title;
// 		    //分割字符串--->字符数组
// 		    var arr=title.split("");
// 		    //删除第一个元素并返回该元素
// 		    var e=arr.shift();
// 		    //把一个对象添加到数组末尾
// 		    arr.push(e);
// 		    //把数组转换成字符串
// 		    var marquee=arr.join("");
// 		    //返回给浏览器
// 		    document.title=marquee;
// 		    //定时一直执行
// 		    window.setTimeout("init()",1000);
// 		}
// 		window.onload=init;
	 
</script>
</body>

</html>
